<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>统计专题图</title>

    <link href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="http://cdn.bootcss.com/openlayers/4.2.0/ol.css" rel="stylesheet">
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%">
<div id="map" style="width: 100%;height:100%"></div>

<script src="http://cdn.bootcss.com/openlayers/4.2.0/ol.js"></script>
<script type="text/javascript" src="../../dist/iclient9-openlayers.min.js"></script>
<script type="text/javascript">
    var map, themeLayer, options,
        url = "http://support.supermap.com.cn:8090/iserver/services/map-jingjin/rest/maps/京津地区人口分布图_专题图";
    var mapService = new ol.supermap.MapService(url);
    mapService.getMapInfo(function (serviceResult) {
        var mapJSONObj = serviceResult.result;
        map = new ol.Map({
            target: 'map',
            controls: ol.control.defaults({attributionOptions: {collapsed: false}})
                .extend([new ol.supermap.control.Logo()]),
            view: new ol.View({
                center: [117, 40],
                zoom: 7,
                projection: "EPSG:4326"
            })
        });
        options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj);
        var layer = new ol.layer.Tile({
            source: new ol.source.TileSuperMapRest(options)
        });
        map.addLayer(layer)
        createTheme();
    });

    function createTheme() {
        var themeGraph = new SuperMap.ThemeGraph({
            items: [
                new SuperMap.ThemeGraphItem({
                    caption: "1992-1995人口增长率",
                    graphExpression: "Pop_Rate95",
                    uniformStyle: new SuperMap.ServerStyle({
                        fillForeColor: new SuperMap.ServerColor(92, 73, 234),
                        lineWidth: 0.1
                    })
                }),
                new SuperMap.ThemeGraphItem({
                    caption: "1995-1999人口增长率",
                    graphExpression: "Pop_Rate99",
                    uniformStyle: new SuperMap.ServerStyle({
                        fillForeColor: new SuperMap.ServerColor(211, 111, 240),
                        lineWidth: 0.1
                    })
                })
            ],
            barWidth: 0.03,
            graduatedMode: SuperMap.GraduatedMode.SQUAREROOT,
            graphAxes: new SuperMap.ThemeGraphAxes({
                axesDisplayed: true
            }),
            graphSize: new SuperMap.ThemeGraphSize({
                maxGraphSize: 1,
                minGraphSize: 0.35
            }),
            graphText: new SuperMap.ThemeGraphText({
                graphTextDisplayed: true,
                graphTextFormat: SuperMap.ThemeGraphTextFormat.VALUE,
                graphTextStyle: new SuperMap.ServerTextStyle({
                    sizeFixed: true,
                    fontHeight: 9,
                    fontWidth: 5
                })
            }),
            graphType: SuperMap.ThemeGraphType.BAR3D
        });
        var themeParameters = new SuperMap.ThemeParameters({
            themes: [themeGraph],
            dataSourceNames: ["Jingjin"],
            datasetNames: ["BaseMap_R"]
        });

        var extent = [114.59, 37.76, 119.51, 42.31];
        new ol.supermap.ThemeService(url).getThemeInfo(themeParameters, function (serviceResult) {
            var result = serviceResult.result;
            if (result && result.newResourceID) {
                themeLayer = new ol.layer.Tile({
                    source: new ol.source.TileSuperMapRest({
                        url: url,
                        noWrap: true,
                        cacheEnabled: false,
                        tileGrid: new ol.tilegrid.TileGrid({
                            extent: extent,
                            resolutions: options.tileGrid.getResolutions()
                        }),
                        layersID: result.newResourceID,
                        transparent: true
                    })
                });
                map.addLayer(themeLayer);
            }
        });
    }
</script>
</body>
</html>